pub mod test_jk;

use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use test_jk::ver_callback::InitCallbackImpl;
use tokio::join;
use crate::ltrail::linterface::InitCallback;
use test_jk::license_ver::VerLicense;
use test_jk::ntp_ver::NtpVerObj;

pub fn test001(){
    // let call_listener: Arc<Mutex<dyn InitCallback + 'static>> = Arc::new(Mutex::new(InitCallbackImpl{}));

    // let license_obj = VerLicense::new(String::from("com.citc.rcs"), String::from("12581"), 0);


    // license_obj.verfiy(call_listener.clone());
    // license_obj.dowload_license(call_listener.clone());
    // license_obj.verfiy(call_listener.clone());

    // thread::sleep(Duration::from_secs(6));

//    let rt = tokio::runtime::Runtime::new().unwrap();
//    rt.block_on(async {
//         let obj = NtpVerObj{address:String::from("value"), name:String::from("value")};
//         obj.ntp_time(call_listener).await;
//    });

//    let rt2 = tokio::runtime::Builder::new_multi_thread()
//                 .worker_threads(3)  // num_cpus::get()
//                 .enable_all().build().expect("创建失败。");
//    rt2.block_on(async move{
//         let obj = NtpVerObj{address:String::from("value"), name:String::from("value")};
//         obj.ntp_time(call_listener.clone()).await;
//    });

// let rt2 = tokio::runtime::Builder::new_current_thread()
//                 .enable_all()
//                 .build().expect("创建失败。");
//    rt2.block_on(async move{
//     println!("开启了单线程异步");
//         let obj = NtpVerObj{address:String::from("value"), name:String::from("value")};
//         let aw01 = obj.ntp_time(call_listener.clone());
//         let aw02 = obj.ntp_time2(call_listener.clone());
//         join!(aw01,aw02)
//    });
//    println!("运行中");
 
   ///// 观察者模式测试
   let test02 =  Test02{};
    test02.observer_data();
    Test01{}.send_data();
}

use crate::livebus::{LiveBus, LiveBusSync, LiveDataParam};

struct Test01 {

}

impl Test01 {

    fn send_data(&self){
        // LiveBus::get_instance().lock().unwrap().send_data(LiveDataParam::MYTEST, "wo xi huan ni.");
        LiveBusSync::get_instance().lock().unwrap().send(LiveDataParam::MYTEST, "wo xi huan ni.");
    }
}
struct Test02 {

}

impl Test02 {

  pub(crate)  fn observer_data(&self){
      // LiveBus::get_instance().lock().unwrap().observer(LiveDataParam::MYTEST, |data|{
      //       println!(" 观察者模式，打印输出：{} ",data);
      //   });

      LiveBusSync::get_instance().lock().unwrap().observer(LiveDataParam::MYTEST,  |data|{
          println!(" 观察者模式，打印输出：{} ",data);
      });
  }
}






























